<%@page import="java.util.Date"%>
<%@ page import="java.text.SimpleDateFormat" %>
       <%
            Date today=new java.util.Date();
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
            
       %>
<script type="text/javascript" >
           function update(){
//               var inputs = document.getElementsByTagName("input");
               if(document.getElementById('picker').checked){
                        document.getElementById('salesform2').style.visibility="visible";
                        document.getElementById('salesform1').style.visibility="collapse";
                        document.getElementById('ButtonCreationDemoButton').type='hidden';
                        document.getElementById('srSubmit').type='hidden';
                        document.getElementById('sr1Submit').type='submit';
               }else{
                        document.getElementById('salesform2').style.visibility="collapse";
                        document.getElementById('salesform1').style.visibility="visible";
                        document.getElementById('ButtonCreationDemoButton').type='text';
                        document.getElementById('srSubmit').type='submit';
                        document.getElementById('sr1Submit').type='hidden';
               }
      
   }
            function yearChange(str){
                if(str!='None')
                    for(var i=0;i<12;i++)
                        document.getElementById("month"+i).style.display="block";
                else{
                    for(var i=0;i<12;i++)
                        document.getElementById("month"+i).style.display="none";
                    document.getElementById("month").selected="selected";
                    
                    for(var i=0;i<31;i++)
                        document.getElementById("day"+i).style.display="none";
                    document.getElementById("day").selected="selected";
                }
            }
            function monthChange(str){
                if(str!='None'){
                    for(var i=0;i<31;i++)
                        document.getElementById("day"+i).style.display="none";
                    
                    if(str==2)
                        for(var i=0;i<29;i++)
                            document.getElementById("day"+i).style.display="block";
                    else if(str==4||str==6||str==9||str==11)
                        for(var i=0;i<30;i++)
                            document.getElementById("day"+i).style.display="block";
                    else
                        for(var i=0;i<31;i++)
                            document.getElementById("day"+i).style.display="block";
                }else{
                    for(var i=0;i<31;i++)
                        document.getElementById("day"+i).style.display="none";
                    document.getElementById("day").selected="selected";
                }
            }
       </script>
       <form>
           <fieldset>
               <center><input type="radio" name="option" checked="checked" onchange="update()" id="calendar" /> <font>Calendar</font>
                   <input type="radio" name="option" onchange="update()" id="picker" /> <font>Picker</font></center>
                   </fieldset>
       </form> 
       <font>Date:</font>
        <form id="salesform1" style="visibility: visible;" action="salesreport.html">
        <input type="text" name="sr" id="ButtonCreationDemoButton" value="<%= format.format(today) %>" />
        <input style="margin-top: 5px" type="submit" id="srSubmit" name="srSubmit" value="Show Report" />
    </form>
        
        <%-- below is for the text only --%>
        <%--<form action="salesreport1.html">
        <input type="hidden" name="sr1" id="ButtonCreationDemoButton1"/>
        <input style="margin-top: 5px" type="hidden" id="sr1Submit" name="sr1Submit" value="Show Report" />
    </form>--%>
        <form id="salesform2" style="visibility: collapse;" action="salesreport1.html">
            <table>
                
        <tr><td> <select name="year">
                    <option onclick="yearChange('None')" value="None" selected="selected" >Year</option>
            <%
            String[] temp=format.format(today).split("-");
            int year=Integer.parseInt(temp[0]);
            for(int i=0;i<20;i++)
            {
                out.println("<option onclick=\"yearChange('"+(year-i)+"')\" value=\""+(year-i)+"\">"+(year-i)+"</option>");
            }
            %>
         </select></td>
        
        <td><select name="month">
                <option id="month" onclick="monthChange('None')" value="None" selected="selected" >Mon</option>
            <%
            for(int i=0;i<12;i++)
            {
                if(i<9)
                    out.println("<option id=\"month"+i+"\" onclick=\"monthChange('"+(i+1)+"')\" style=\"display: none\" value=\"0"+(i+1)+"\">0"+(i+1)+"</option>");
                else
                    out.println("<option id=\"month"+i+"\" onclick=\"monthChange('"+(i+1)+"')\" style=\"display: none\" value=\""+(i+1)+"\">"+(i+1)+"</option>");
            }
            %>
         </select></td>
        
        <td><select name="day">
                    <option id="day" value="None" selected="selected" >Day</option>
            <%
            for(int i=0;i<31;i++)
            {
                if(i<9)
                    out.println("<option id=\"day"+i+"\" style=\"display: none\" value=\"0"+(i+1)+"\">0"+(i+1)+"</option>");
                else
                    out.println("<option id=\"day"+i+"\" style=\"display: none\" value=\""+(i+1)+"\">"+(i+1)+"</option>");
            }
            %>
         </select></td></tr>
        
        </table>
        
        <input style="margin-top: 5px" type="hidden" id="sr1Submit" name="sr1Submit" value="Show Report" />
    </form>
        <script >
                AnyTime.picker('ButtonCreationDemoButton',
      {
          format:"%Y-%m-%d"
      });
        
    </script>